import {AfterViewInit, Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {ChartService} from '../../services/chart/chart.service';
import {TranslateService} from '@ngx-translate/core';

declare var $: any;
@Component({
  selector: 'app-widget-echart',
  templateUrl: './widget-echart.component.html',
  styleUrls: ['./widget-echart.component.css']
})
export class WidgetEchartComponent implements OnInit,AfterViewInit {
  @Input()  widget: any;
  @Input()  row: any;
  @Output() onRenderComplete = new EventEmitter<any>();
  @Output() onReloadEvent = new EventEmitter<any>();
  public myheight;
  public x = false;
  constructor(
    private chartService: ChartService,
    public translate:TranslateService
  ) {
    translate.addLangs(['zh','en']);                          //添加语言支持
    translate.setDefaultLang('en');                           //设置默认语言
    let broswerLang = translate.getBrowserLang();              //获取浏览器支持的语言
    console.log(broswerLang)                                   //zh
    translate.use(broswerLang.match(/zh|en/) ? broswerLang : 'en');
  }

  ngOnInit() {
    // var template = $templateCache.get("echartContent");
    this.myheight = this.row.height ? (this.row.height - 44) : 300;
    // var link = $compile(template);
    // console.log(link);
    // this.widget.render($('.box-body'), null, null);
  }
  public ngAfterViewInit() {
    // let idname = 'id-' + this.widget.widgetId;
    // this.chartService.render($('#'+idname), this.widget.widget.data, function (option) {
    // }, null,true,null, null);
    this.onRenderComplete.emit(this.widget);
  }
  public reload(){
    this.widget.loading = true;
    let idname = 'id-' + this.widget.widgetId;
    this.onReloadEvent.emit(this.widget);
  }
}
